//
//  DKFaqAlertView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/8.
//

#import "DKFaqAlertView.h"
@interface DKFaqAlertView()
@property (nonatomic, weak)zhPopupController * dk_FaqAlertViewPop;
@property (nonatomic,strong) DKFaqAlertView *dk_FaqAlertView;
@property (nonatomic, strong)UILabel * dk_LoginAgreenHeadLab;
@property (nonatomic, copy) void(^ComplictBlock)(void);
@end
@implementation DKFaqAlertView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_LoginAgreenHeadLab = [[UILabel alloc] init];
    self.dk_LoginAgreenHeadLab.textColor = DK_Hex(@"#333333");
    self.dk_LoginAgreenHeadLab.font = DK_FONT_Regular(14);
    self.dk_LoginAgreenHeadLab.numberOfLines = 0;
    [self addSubview:self.dk_LoginAgreenHeadLab];
    [self.dk_LoginAgreenHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(51)));
        make.bottom.equalTo(@(-DK_IsWidthScale(39)));
        make.left.equalTo(@(DK_IsWidthScale(25)));
        make.right.equalTo(@(-DK_IsWidthScale(25)));
    }];
    
    //close
    UIButton * dk_LoginCloseBtn = [[UIButton alloc] init];
    [dk_LoginCloseBtn setBackgroundImage:DK_GetImage(@"dk_LoginAgreementClose") forState:UIControlStateNormal];
    [dk_LoginCloseBtn addTarget:self action:@selector(goCancle) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_LoginCloseBtn];
    [dk_LoginCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(17)));
        make.width.equalTo(@(DK_IsWidthScale(17)));
    }];
}
- (void)goCancle{
    [_dk_FaqAlertViewPop dismiss];
}
- (void)layoutSublayersOfLayer:(CALayer *)layer{
    [super layoutSublayersOfLayer:layer];
    [self makeCornerOnTopleftRight:DK_IsWidthScale(50)];
}
+ (void)dk_ShowFaqAlertViewComplete:(NSString *)alertTitle complete:(void(^)(void))complete{
    DKFaqAlertView * dk_FaqAlertView = [[DKFaqAlertView alloc] init];
    NSMutableAttributedString * attritedString = [[[NSAttributedString alloc]initWithData:[alertTitle dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil] mutableCopy];
    [attritedString addAttributes:@{NSFontAttributeName:DK_FONT_Regular(14)} range:NSMakeRange(0, attritedString.length)];
//    CGFloat faqAlertH = [NSString getContentSize:alertTitle withFont:DK_FONT_Regular(14) withSize:CGSizeMake(DK_SCREEN_W - DK_IsWidthScale(49), CGFLOAT_MAX)].height;
    CGFloat faqAlertH = [NSString getContentAttributedSize:attritedString withSize:CGSizeMake(DK_SCREEN_W - DK_IsWidthScale(50), CGFLOAT_MAX)].height+1;
    zhPopupController * sureAgreemnetCtrl = [[zhPopupController alloc] initWithView:dk_FaqAlertView size:CGSizeMake(DK_SCREEN_W, faqAlertH + DK_IsWidthScale(90)+DK_SafeAreaBottom)];
    dk_FaqAlertView.ComplictBlock = complete;
    dk_FaqAlertView.dk_LoginAgreenHeadLab.attributedText = attritedString;
    sureAgreemnetCtrl.presentationStyle = zhPopupSlideStyleTransform;
    sureAgreemnetCtrl.layoutType = zhPopupLayoutTypeBottom;
    sureAgreemnetCtrl.presentationTransformScale = 0.56;
    sureAgreemnetCtrl.dismissonTransformScale = 0.56;
    sureAgreemnetCtrl.dismissOnMaskTouched = NO;
    dk_FaqAlertView.dk_FaqAlertViewPop = sureAgreemnetCtrl;
    [sureAgreemnetCtrl showInView:((AppDelegate*)([UIApplication sharedApplication].delegate)).window completion:^{
    }];
}
@end
